<template>
  <div class="butt-list-sty">
    <div class="butt-list-sty-wrap">
      <div
        v-for="(item, index) in topitemSelectList"
        :key="item.equipmentTypeCode"
        :class="index === itemtypeactive ? 'basebut1' : 'basebut2'"
        @click="itemtypeactive = index"
      >{{ item.equipmentTypeName }}</div>
    </div>
  </div>
</template>

<script>
// import equipTypeApi from "@/api/processing-management/equip-manage/equip-type/index";

export default {
  props: {
    groupId: {
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      itemtypeactive: 0,
      topitemSelectList: [],
      groupIndexItem: true
    };
  },
  watch: {
    itemtypeactive(newvalue) {
      this.selbut(newvalue);
    },
    groupId(e) {
      if (e) {
        this.itemtypeactive = 0;
        this.topitemSelectList = [];
        this.groupIndexItem = true;
        this.queryEquipmentTypeList(e);
      }
    }
  },
  created() {},
  mounted() {
    // setTimeout(() => {
    //   this.selbut(0);
    // }, 200)
  },
  methods: {
    selbut(i) {
      setTimeout(() => {
        if (this.topitemSelectList[i]) {
          this.$emit(
            "topitemtypes",
            this.topitemSelectList[i]["equipmentTypeCode"]
          );
        }
      }, 300);
    },
    queryEquipmentTypeList(e) {
      if (e === 11111) {
        this.topitemSelectList = [
          { equipmentTypeCode: 1, equipmentTypeName: "收割机" },
          { equipmentTypeCode: 2, equipmentTypeName: "拖拉机" }
        ];
      } else {
        this.topitemSelectList = [
          { equipmentTypeCode: 1, equipmentTypeName: "收割111机" },
          { equipmentTypeCode: 2, equipmentTypeName: "拖111拉机" }
        ];
      }
      // let params = {
      //   organizationId: sessionStorage.organizationId,
      //   equipmentTypeCode: e
      // }
      // equipTypeApi.queryParentList(params).then(res => {
      //   // 赋值数组
      //   if (res.code === 1) {
      //     let data = res.data || [];
      //     this.topitemSelectList = data;
      //     if (this.topitemSelectList.length > 0) {
      this.selbut(0);
      //     }
      //   }
      // })
    }
  }
};
</script>
<style lang="scss" scoped>
.butt-list-sty {
  width: calc(100% - 40px);
  padding: 0 20px;
  position: absolute;
  top: -26px;
  overflow: hidden;
}
.butt-list-sty-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
}
.basebut1 {
  height: 36px;
  line-height: 36px;
  font-size: 17px;
  text-align: center;
  background-image: linear-gradient(#0fa1d2, #1087af, #106f8f);
  border: #f6f9f9 1px solid;
  border-radius: 30px;
  color: #ffffff;
  cursor: pointer;
  margin: 3px 5px;
  padding: 0 40px;
  white-space: nowrap;
  // transform: translateY(50%);
}
.basebut2 {
  // width: 120px;
  height: 35px;
  line-height: 35px;
  font-size: 17px;
  text-align: center;
  background-color: #106986;
  border-radius: 30px;
  color: #ffffff;
  cursor: pointer;
  margin: 3px 5px;
  padding: 0 40px;
  white-space: nowrap;
  // transform: translateY(50%);
}
</style>
